using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VVKUMASS
    {
        public DataRow Convert2VKUMASS(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryVKUMASS(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["VKUMANDANT"] = " ".PadRight(2 ); 
         dwReturn["VKUAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["VKUAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["VKUAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["VKUUPOS"] = " ".PadRight(3 ); 
         dwReturn["VKUAENDZL"] = " ".PadRight(0 ); 
         dwReturn["VKUAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["VKUAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["VKUNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["VKUNEUDAT"] = " ".PadRight(0 ); 
         dwReturn["VKULAENGE"] = " ".PadRight(0 ); 
         dwReturn["VKUBREITE"] = " ".PadRight(0 ); 
         dwReturn["VKUZEICH"] = " ".PadRight(14 ); 
         dwReturn["VKUSPOS"] = " ".PadRight(3 ); 
         dwReturn["VKUSTKNR"] = " ".PadRight(12 ); 
         dwReturn["VKUPAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["VKUPAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["VKUPAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["VKUPUMASS"] = " ".PadRight(3 ); 
         dwReturn["VKUFILLER"] = " ".PadRight(29 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapVKUMASS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveVKUMASS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVKUMASS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapVKUMASS(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertVKUMASS(dwLocal, ITXDBVERSION);
            }
            UpdateVKUMASS(dwLocal);
        }
        public void InsertVKUMASS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO VKUMASS(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryVKUMASS(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM VKUMASS WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM VKUMASS  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "VKUMASS";
            Return = Result;
            return Return;
        }
        public void DeleteVKUMASS(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM VKUMASS   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateVKUMASS(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE VKUMASS SET "
                    +"VKUMANDANT= :VKUMANDANT,"
                    +"VKUAUFKRS= :VKUAUFKRS,"
                    +"VKUAUFLFD= :VKUAUFLFD,"
                    +"VKUAUFPOS= :VKUAUFPOS,"
                    +"VKUUPOS= :VKUUPOS,"
                    +"VKUAENDZL= :VKUAENDZL,"
                    +"VKUAENDBEN= :VKUAENDBEN,"
                    +"VKUAENDDAT= :VKUAENDDAT,"
                    +"VKUNEUBEN= :VKUNEUBEN,"
                    +"VKUNEUDAT= :VKUNEUDAT,"
                    +"VKULAENGE= :VKULAENGE,"
                    +"VKUBREITE= :VKUBREITE,"
                    +"VKUZEICH= :VKUZEICH,"
                    +"VKUSPOS= :VKUSPOS,"
                    +"VKUSTKNR= :VKUSTKNR,"
                    +"VKUPAUFKRS= :VKUPAUFKRS,"
                    +"VKUPAUFLFD= :VKUPAUFLFD,"
                    +"VKUPAUFPOS= :VKUPAUFPOS,"
                    +"VKUPUMASS= :VKUPUMASS,"
                    +"VKUFILLER= :VKUFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("VKUMANDANT", OracleType.NVarChar).Value = dwData["VKUMANDANT"].ToString(); 
          or1.Parameters.Add("VKUAUFKRS", OracleType.NVarChar).Value = dwData["VKUAUFKRS"].ToString(); 
          or1.Parameters.Add("VKUAUFLFD", OracleType.NVarChar).Value = dwData["VKUAUFLFD"].ToString(); 
          or1.Parameters.Add("VKUAUFPOS", OracleType.NVarChar).Value = dwData["VKUAUFPOS"].ToString(); 
          or1.Parameters.Add("VKUUPOS", OracleType.NVarChar).Value = dwData["VKUUPOS"].ToString(); 
          or1.Parameters.Add("VKUAENDZL", OracleType.NVarChar).Value = dwData["VKUAENDZL"].ToString(); 
          or1.Parameters.Add("VKUAENDBEN", OracleType.NVarChar).Value = dwData["VKUAENDBEN"].ToString(); 
          or1.Parameters.Add("VKUAENDDAT", OracleType.NVarChar).Value = dwData["VKUAENDDAT"].ToString(); 
          or1.Parameters.Add("VKUNEUBEN", OracleType.NVarChar).Value = dwData["VKUNEUBEN"].ToString(); 
          or1.Parameters.Add("VKUNEUDAT", OracleType.NVarChar).Value = dwData["VKUNEUDAT"].ToString(); 
          or1.Parameters.Add("VKULAENGE", OracleType.NVarChar).Value = dwData["VKULAENGE"].ToString(); 
          or1.Parameters.Add("VKUBREITE", OracleType.NVarChar).Value = dwData["VKUBREITE"].ToString(); 
          or1.Parameters.Add("VKUZEICH", OracleType.NVarChar).Value = dwData["VKUZEICH"].ToString(); 
          or1.Parameters.Add("VKUSPOS", OracleType.NVarChar).Value = dwData["VKUSPOS"].ToString(); 
          or1.Parameters.Add("VKUSTKNR", OracleType.NVarChar).Value = dwData["VKUSTKNR"].ToString(); 
          or1.Parameters.Add("VKUPAUFKRS", OracleType.NVarChar).Value = dwData["VKUPAUFKRS"].ToString(); 
          or1.Parameters.Add("VKUPAUFLFD", OracleType.NVarChar).Value = dwData["VKUPAUFLFD"].ToString(); 
          or1.Parameters.Add("VKUPAUFPOS", OracleType.NVarChar).Value = dwData["VKUPAUFPOS"].ToString(); 
          or1.Parameters.Add("VKUPUMASS", OracleType.NVarChar).Value = dwData["VKUPUMASS"].ToString(); 
          or1.Parameters.Add("VKUFILLER", OracleType.NVarChar).Value = dwData["VKUFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
